package com.qf.controller;

import com.qf.pojo.Books;
import com.qf.pojo.req.BookType;
import com.qf.service.BookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class BookController {
    @Resource
    BookService bookService;
    @RequestMapping("/findBookByBcid/{bcid}")
    public List<BookType> findBookByBcid(@PathVariable("bcid")Integer bcid){
        return bookService.findBookByBcid(bcid);
    }


    @RequestMapping("/findBookByBid/{bid}")
    public BookType findBookByBid(@PathVariable("bid")Integer bid){
        return bookService.findBookByBid(bid);
    }


    @RequestMapping(value = "/addBooks",method = RequestMethod.POST)
    public int addBooks(@RequestBody Books books){
        int add = bookService.add(books);
        if (add>0){
            return 1;
        }else {
            return 0;
        }
    }
    @RequestMapping(value = "/updateBooks",method = RequestMethod.POST)
    public int updateBooks(@RequestBody Books books){
        int update = bookService.update(books);
        if (update>0){
            return 1;
        }else {
            return 0;
        }
    }

    @RequestMapping("/deleteBooks/{bid}")
    public int deleteBooks(@PathVariable("bid")int bid) {
        int delete = bookService.delete(bid);
        if (delete>0){
            return 1;
        }else {
            return 0;
        }
    }
    @RequestMapping("/findBook")
    public List<Books> findBook(){
        return bookService.findAll();
    }

    @RequestMapping("/findByBid/{bid}")
    public Books findByBid(@PathVariable("bid") int bid){
        return bookService.findByBid(bid);
    }


}
